<template>
	<view class="main">
		<!-- #ifdef MP-WEIXIN -->
		<image class="bg" src="@/static/img/image3.png" mode=""></image>
		<!-- #endif -->
		<view class="header">
			<text>积分总数</text>
			<text>{{info.hasscore}}</text>
		</view>
		<view class="list">
			<view class="tit">
				账单明细
			</view>
			<view class="itemBox">
				<u-empty v-if="list.length == 0" text="暂无流水" mode="data"
					icon="http://cdn.uviewui.com/uview/empty/data.png">
				</u-empty>
				<view class="item" v-for="(item,index) in list" :key="index">
					<view class="left">
						<text>{{item.change_type}} {{item.username}}</text>
						<text>{{item.createtime}}</text>
					</view>
					<view class="right">
						<text v-if="item.record_type == 1">+</text>
						<text v-if="item.record_type == 0">-</text>
						{{item.money}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		user,
		moneyChanges
	} from '@/api/index.js'
	export default {
		data() {
			return {
				info: {},
				list: [],
				page: 1,
				last_page: null
			}
		},
		onReachBottom() {
			if (this.page == this.last_page) {
				uni.showToast({
					title: '已经是最后一页了',
					icon: 'none'
				})
			} else {
				this.page++
				this.getList()
			}
		},
		onLoad() {
			this.getInfo()
		},
		onShow() {
			this.getList()
		},
		methods: {
			async getList() {
				if (this.page == 1) {
					this.list = []
				}
				let res = await moneyChanges({
					page_size: 15,
					moneytype: 1,
					changetype: -1,
					page: this.page
				})
				res.data.data.forEach(item => {
					this.list.push(item)
				})
				this.last_page = res.data.last_page
			},
			async getInfo() {
				let res = await user()
				console.log(res)
				this.info = res.data
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		position: relative;
		background-image: url(@/static/img/image3.png);
		background-size: 100% 604rpx;
		background-repeat: no-repeat;
		background-position: top left;
		min-height: 100vh;
		background-color: #f6f6f6;
		display: flex;
		flex-direction: column;
		.bg{
			width: 100%;
			height: 604rpx;
			top: 0;
			left: 0;
			position: absolute;
			// z-index: -1;
		}

		.header {
			position: relative;
			z-index: 10;
			display: flex;
			flex-direction: column;
			padding: 100rpx 50rpx;

			text:first-child {
				color: #DCFFCB;
				font-size: 28rpx;
				margin-bottom: 30rpx;
			}

			text:last-child {
				color: #000;
				font-size: 60rpx;
			}
		}

		.list {
			position: relative;
			z-index: 10;
			flex: 1;
			padding: 40rpx;
			background-color: #fff;
			border-radius: 30rpx 30rpx 0 0;

			.tit {
				color: #ea504f;
				font-size: 32rpx;
				margin-bottom: 60rpx;
			}

			.itemBox {
				.item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					color: #000;
					margin-bottom: 20rpx;

					.left {
						display: flex;
						flex-direction: column;

						text:first-child {
							font-size: 32rpx;
							margin-bottom: 20rpx;
						}

						text:last-child {
							font-size: 26rpx;
							color: #666;
						}
					}

					.right {
						font-weight: 700;
					}
				}
			}
		}
	}
</style>